package com.intretech.umsin.oss.config;

import com.aliyun.oss.OSSClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version V1.0
 * @ClassName: AliyunOSSConfig
 * @Description: AliyunOSSConfig 服务实现
 * @author: 李启联
 * @date: 2022-04-25 15:49
 * @Copyright: Copyright (c) 2022
 */
@Configuration
@ConfigurationProperties(prefix = "aliyun.oss", ignoreUnknownFields = true)
@ConditionalOnProperty(name = "oss-type",havingValue = "ALIYUN",matchIfMissing = false)
public class AliyunOSSConfig {

    private String endpoint;

    private String accessKeyId;

    private String accessKeySecret;

    private String bucketName;

    private String filehost;

    public String getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public String getFilehost() {
        return filehost;
    }

    public void setFilehost(String filehost) {
        this.filehost = filehost;
    }

    public AliyunOSSConfig() {
    }

    @Override
    public String toString() {
        return "AliyunOSSConfig{" +
                "endpoint='" + endpoint + '\'' +
                ", accessKeyId='" + accessKeyId + '\'' +
                ", accessKeySecret='" + accessKeySecret + '\'' +
                ", bucketName='" + bucketName + '\'' +
                ", filehost='" + filehost + '\'' +
                '}';
    }

    @Bean
    public OSSClient getOSSClient(){
        return new OSSClient(getEndpoint(),getAccessKeyId() ,getAccessKeySecret());
    }
}
